<template>
  <el-main>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/device' }"
        >设备管理
      </el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/device/bind' }"
        >设备列表
      </el-breadcrumb-item>
      <el-breadcrumb-item>设备详情</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="margin-top-20">
      <el-card shadow="never">
        <h4
          class="margin-bottom-20"
          style="border-left: 3px solid #00a7cd;padding-left: 8px;"
        >
          基本信息：
        </h4>
        <el-form inline label-width="120px">
          <el-form-item class="m-input-400" label="设备类型">
            {{ form.deviceTypeDesc }}
          </el-form-item>
          <el-form-item class="m-input-400" label="通信方式">
            {{ form.deviceSocketDesc }}
          </el-form-item>
          <el-form-item class="m-input-400" label="imei">
            {{ form.imei }}
          </el-form-item>
          <el-form-item class="m-input-400" label="设备波段">
            {{ form.waveLength }}(MHz)
          </el-form-item>
          <el-form-item class="m-input-400" label="剩余时长">
            {{ form.initDate }}(天)
          </el-form-item>
          <el-form-item class="m-input-400" label="平台信息">
            {{ form.platformTypeDesc }}
          </el-form-item>
          <el-form-item class="m-input-400" label="所属企业">
            {{ form.companyName }}
          </el-form-item>
          <el-form-item class="m-input-400" label="设备状态">
            <el-tag disable-transitions type="success" v-if="!form.isLock">
              在线
            </el-tag>
            <el-tag disable-transitions type="danger" v-else>
              离线
            </el-tag>
          </el-form-item>
          <el-form-item class="m-input-400" label="创建时间">
            {{ form.ctime }}
          </el-form-item>
          <el-form-item class="m-input-400" label="备注">
            {{ form.remarks }}
          </el-form-item>
        </el-form>
        <h4
          class="margin-bottom-20"
          style="border-left: 3px solid #00a7cd;padding-left: 8px;"
        >
          详细信息：
        </h4>
        <el-form inline label-width="120px">
          <el-form-item class="m-input-400" label="满溢"> </el-form-item>
          <el-form-item class="m-input-400" label="高度"> </el-form-item>
          <el-form-item class="m-input-400" label="起火"> </el-form-item>
          <el-form-item class="m-input-400" label="温度"> </el-form-item>
          <el-form-item class="m-input-400" label="倾倒"> </el-form-item>
          <el-form-item class="m-input-400" label="倾倒角度"> </el-form-item>
          <el-form-item class="m-input-400" label="监测时间"> </el-form-item>
          <el-form-item class="m-input-400" label="倾计数器"> </el-form-item>
          <el-form-item class="m-input-400" label="RSRP"> </el-form-item>
          <el-form-item class="m-input-400" label="坐标经度"> </el-form-item>
          <el-form-item class="m-input-400" label="坐标纬度"> </el-form-item>
        </el-form>
      </el-card>
    </div>
  </el-main>
</template>

<script>
export default {
  data() {
    return {
      id: null,
      form: {
        deviceTypeDesc: null,
        deviceSocketDesc: null,
        imei: null,
        waveLength: null,
        platformTypeDesc: null,
        remarks: null
      }
    };
  },
  mounted() {
    this.id = this.$route.params.id;
    this.info();
  },
  methods: {
    info() {
      this.$ajax.device_bind
        .info(this.id)
        .then(result => {
          if (result.code == 1) {
            this.form = result.data;
          } else {
            this.$message({
              message: result.msg,
              type: "warning"
            });
          }
        })
        .catch(e => {
          console.log(e);
        });
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          let loadingInstance = this.$loading({ fullscreen: true });
          this.$ajax.device_unbind
            .update(this.form)
            .then(result => {
              if (result.code != 1) {
                this.$message({
                  message: result.msg,
                  type: "warning"
                });
              } else {
                this.$message({
                  type: "success",
                  message: "修改设备信息成功!"
                });
                this.$router.push("/device/unbind/");
              }
            })
            .catch(e => {
              console.log(e);
              this.$message({
                message: "系统繁忙，请稍后重试",
                type: "warning"
              });
            })
            .finally(function() {
              loadingInstance.close();
            });
        } else {
          return false;
        }
      });
    },
    cancelForm() {
      this.$router.push("/device/unbind");
    }
  }
};
</script>
